﻿package mortal.game.view.copy.crossMainCity.mainCityPosition
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.mvc.core.*;

    public class MainCityPostRender extends GSprite
    {
        private var _openDoubleActiveBtn:GLoadingButton;
        private var _guildName:GTextFiled;
        private var _playerName:GButton;
        private var _miniPlayer:SMiniPlayer;
        private var _combate:BitmapNumberText;
        private var _playerBg:GImageBitmap;

        public function MainCityPostRender()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.MainCityPostInfoBg, 25, -15, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.MainCityPostTxt1, 36, 60, this));
            var _loc_1:* = GlobalStyle.textFormatHuang2.center();
            _loc_1.size = 15;
            this._playerBg = UIFactory.gImageBitmap("", -25, -180, this);
            this._guildName = UIFactory.gTextField("", 0, 0, 200, 50, this, _loc_1);
            this._playerName = UIFactory.gButton(Language.getString(35214), 0, 20, 200, 50, this, "GreenLinkButtonSize14");
            this._playerName.configEventListener(MouseEvent.CLICK, this.checkPlayerInfo);
            this._combate = UIFactory.bitmapNumberText(85, 60, "GuildNSkillLevelNum.png", 13, 16, -2, this, 13, BitmapNumberText.Left);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._playerBg.dispose(param1);
            this._playerBg = null;
            this._guildName.dispose(param1);
            this._guildName = null;
            this._playerName.dispose(param1);
            this._playerName = null;
            this._combate.dispose(param1);
            this._combate = null;
            if (this._openDoubleActiveBtn)
            {
                this._openDoubleActiveBtn.dispose(param1);
                this._openDoubleActiveBtn = null;
            }
            this._miniPlayer = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function checkPlayerInfo(event:MouseEvent) : void
        {
            if (this._miniPlayer)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.LookPlayerInfo, this._miniPlayer.entityId));
            }
            return;
        }// end function

        private function addOpenDoubleActiveBtn() : void
        {
            var _loc_1:Boolean = false;
            var _loc_2:SEntityId = null;
            if (this._openDoubleActiveBtn == null)
            {
                this._openDoubleActiveBtn = UIFactory.gLoadingButton(ResFileConst.KqsbjyhdBtn, 23, 55 + 32, 162, 39, null);
                this._openDoubleActiveBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
                this._openDoubleActiveBtn.toolTipData = Language.getString(90480);
                _loc_1 = Cache.instance.expAddition.isOpenWeek;
                _loc_2 = Cache.instance.role.entityInfo.entityId;
                this._openDoubleActiveBtn.filterEnabled = true;
                Dispatcher.addEventListener(EventName.MainCityOpenExpActSuccess, this.doubleActiveSuccess);
            }
            this.addChild(this._openDoubleActiveBtn);
            return;
        }// end function

        private function doubleActiveSuccess(param1 = null) : void
        {
            this._openDoubleActiveBtn.filterEnabled = false;
            MsgManager.showRollTipsMsg(Language.getString(21418));
            Dispatcher.removeEventListener(EventName.MainCityOpenExpActSuccess, this.doubleActiveSuccess);
            return;
        }// end function

        private function onClickHandle(event:MouseEvent) : void
        {
            var str:String;
            var e:* = event;
            if (this._openDoubleActiveBtn == e.target)
            {
                var innerCloseHandler:* = function (param1:int, param2:Object = null) : void
            {
                if (param1 == Alert.OK)
                {
                    GameProxy.expAddition.openExpAct();
                }
                return;
            }// end function
            ;
                str = Language.getString(21419);
                Alert.show(str, null, Alert.OK | Alert.CANCEL, null, innerCloseHandler);
            }
            return;
        }// end function

        private function removeBtn() : void
        {
            if (this._openDoubleActiveBtn)
            {
                this._openDoubleActiveBtn.dispose();
                this._openDoubleActiveBtn = null;
            }
            return;
        }// end function

        private function clearInfo() : void
        {
            this._miniPlayer = null;
            this._guildName.text = Language.getString(21416);
            this._guildName.y = 15;
            this._playerName.label = "";
            this._playerBg.imgUrl = ImagesConst.MainCityKingNo;
            var _loc_1:Number = 0.6;
            this._playerBg.scaleZ = 0.6;
            var _loc_1:* = _loc_1;
            this._playerBg.scaleY = _loc_1;
            this._playerBg.scaleX = _loc_1;
            this._combate.text = "0";
            this.removeBtn();
            return;
        }// end function

        public function set data(param1:SMainCityPositon) : void
        {
            var _loc_2:SMainCityPositons = null;
            if (param1)
            {
                this._miniPlayer = param1.officer;
                _loc_2 = Cache.instance.mainCity.sMainCityPositons;
                this._guildName.text = NameUtil.getProxyName(this._miniPlayer.entityId) + "_" + _loc_2.guildName;
                this._guildName.y = 5;
                this._playerName.y = 10;
                this._playerName.label = this._miniPlayer.name;
                this._combate.text = this._miniPlayer.combat.toString();
                this._playerBg.imgUrl = "";
                if (param1 && param1.positon == EMainCityPosition._EMainCityKing && EntityUtil.isSelf(param1.officer.entityId))
                {
                    this.addOpenDoubleActiveBtn();
                }
                else
                {
                    this.removeBtn();
                }
            }
            else
            {
                this.clearInfo();
            }
            return;
        }// end function

    }
}
